Skip to content

[GEN][ZH] Annotate fallthrough between various switch case labels #1085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2025

Conversation

xezon
Copy link

@xezon xezon commented Jun 19, 2025

This change annotates fallthroughs in GameEngine to suppress warnings and make the intent clear.

GeneralsMD\Code\GameEngine\Source\Common\RandomValue.cpp(387): warning C26819: Unannotated fallthrough between switch labels (es.78).

@xezon xezon added this to the Code foundation build up milestone Jun 19, 2025
@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing labels Jun 19, 2025
@xezon xezon force-pushed the xezon/staticanalysis/001 branch from 812d386 to d88e895 Compare June 20, 2025 07:26
Copy link

@Mauller Mauller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, only a few things that seem odd.

case CHINA_FRIEND:
side.set("China");
break;
case GLA_ENEMY:
isFriend = FALSE;
isFriend = FALSE;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd that it thinks there was a change here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd that it thinks there was a change here.

There's a tab after it in the original line.

Comment on lines 941 to 942
case SCORESCALEUPTRANSITION_2:
case SCORESCALEUPTRANSITION_3:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised it does not warn about these cases falling through.

Comment on lines +642 to 644
FALLTHROUGH;
case 2:
break;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State is not used outside of this function so this seems a bit redundant, case 2 could be removed and a break added at the end of case 1.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are probably right. I think the change as is is sufficient for now, so it is in line with the title of this change.

Comment on lines +145 to 148
FALLTHROUGH;

case FLASHTRANSITION_FADE_IN_2:
case FLASHTRANSITION_FADE_IN_3:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the score scaleup, im surprised it does not complain here, unless it just optimises away empty cases?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it looks like the static analyzer does not care about the fallthrough annotation when there is no body behind the switch case label. It is a very common pattern and I think fallthrough is expected implicitly in this case, so requires no annotation to be clear.

@xezon xezon merged commit 1c8b33d into TheSuperHackers:main Jun 21, 2025
14 checks passed
@xezon xezon deleted the xezon/staticanalysis/001 branch June 21, 2025 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants